package wec_wallet.ebo.com.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.List;

import wec_wallet.ebo.com.R;
import wec_wallet.ebo.com.bean.InterceptDataBean;
import wec_wallet.ebo.com.util.StringUtil;

/**
 * Created by Administrator on 2018/3/14.
 */

public class BlackListAdapter extends BaseAdapter {
    Context context;
    List<InterceptDataBean> list;
    LayoutInflater inflater;

    public BlackListAdapter(Context context) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
    }

    public void setLists(List<InterceptDataBean> lists) {
        this.list = lists;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    class ViewHolder {
        private TextView tv_name, tV_time, tV_cardId, tV_phone, tV_address, tV_gender;
        private RelativeLayout re_address, re_gender;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        InterceptDataBean bean = list.get(i);
        if (view == null) {
            holder = new ViewHolder();
            view = inflater.inflate(R.layout.activity_list_item_blacklist, null);
            holder.re_address = (RelativeLayout) view.findViewById(R.id.rela_blackList_address)
            ;
            holder.re_gender = (RelativeLayout) view.findViewById(R.id.rela_blackList_gender);
            holder.tv_name = (TextView) view.findViewById(R.id.tv_blackList_name);
            holder.tV_time = (TextView) view.findViewById(R.id.tv_blackList_time);
            holder.tV_address = (TextView) view.findViewById(R.id.tv_blackList_address);
            holder.tV_phone = (TextView) view.findViewById(R.id.tv_blackList_phone);
            holder.tV_cardId = (TextView) view.findViewById(R.id.tv_blackList_cardId);
            holder.tV_gender = (TextView) view.findViewById(R.id.tv_blackList_gender);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        holder.tv_name.setText(bean.getName());
        holder.tV_time.setText(bean.getCreated_at());
        holder.tV_cardId.setText(bean.getIdcard());
        holder.tV_phone.setText(bean.getMobile());
        if (StringUtil.isStringEmpty(bean.getOther_contact())) {
            holder.re_address.setVisibility(View.GONE);
        } else {
            holder.re_address.setVisibility(View.VISIBLE);
            holder.tV_address.setText(bean
                    .getOther_contact());

        }
        if (StringUtil.isStringEmpty(bean.getSex())) {
            holder.re_gender.setVisibility(View.GONE);
        } else {
            holder.re_gender.setVisibility(View.VISIBLE);
            if (bean.getSex().equals("0")) {
                holder.tV_gender.setText(context.getString(R.string.report_gender_no));

            } else if (bean.getSex().equals("1")) {
                holder.tV_gender.setText(context.getString(R.string.report_female));
            } else {
                holder.tV_gender.setText(context.getString(R.string.report_male));

            }

        }

        return view;
    }
}
